package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import model.Card;
import controller.GameController;

public class GameDisplay extends Display {
	private GameController gameController;
	private JTextField betField;
	
	// Player name text areas
	private JLabel lblUser;
	private JLabel lblPlayer_1;
	private JLabel lblPlayer_2;
	private JLabel lblPlayer_3;
	private JLabel lblPlayer_4;
	private JLabel lblPlayer_5;
	
	// Player portrait labels
	private JLabel lblUserPortrait;
	private JLabel lblPlayer1Portrait;
	private JLabel lblPlayer2Portrait;
	private JLabel lblPlayer3Portrait;
	private JLabel lblPlayer4Portrait;
	private JLabel lblPlayer5Portrait;
	
	// Money text labels
	private JLabel lblPot;
	private JLabel lblUserMoney;
	private JLabel lblPlayer1Money;
	private JLabel lblPlayer2Money;
	private JLabel lblPlayer3Money;
	private JLabel lblPlayer4Money;
	private JLabel lblPlayer5Money;
	private JLabel lblAnte;
	private JLabel lblMaxBet;
	private JLabel lblAnteValue;
	private JLabel lblMaxBetValue;
	
	// Chat
	private JTextField chatOutgoing;
	private JTextArea chatIncoming;
	private JScrollPane chatIncomingScrollable;
	
	// Card labels for the players at the table
	private JLabel lblUserCard1;
	private JLabel lblUserCard2;
	private JLabel lblUserCard3;
	private JLabel lblUserCard4;
	private JLabel lblUserCard5;
	
	private JLabel lblPlayer1C1;
	private JLabel lblPlayer1C2;
	private JLabel lblPlayer1C3;
	private JLabel lblPlayer1C4;
	private JLabel lblPlayer1C5;
	
	private JLabel lblPlayer2C1;
	private JLabel lblPlayer2C2;
	private JLabel lblPlayer2C3;
	private JLabel lblPlayer2C4;
	private JLabel lblPlayer2C5;
	
	private JLabel lblPlayer3C1;
	private JLabel lblPlayer3C2;
	private JLabel lblPlayer3C3;
	private JLabel lblPlayer3C4;
	private JLabel lblPlayer3C5;
	
	private JLabel lblPlayer4C1;
	private JLabel lblPlayer4C2;
	private JLabel lblPlayer4C3;
	private JLabel lblPlayer4C4;
	private JLabel lblPlayer4C5;
	
	private JLabel lblPlayer5C1;
	private JLabel lblPlayer5C2;
	private JLabel lblPlayer5C3;
	private JLabel lblPlayer5C4;
	private JLabel lblPlayer5C5;
	
	private JButton btnFoldButton;
	private JButton btnCallButton;
	private JButton btnRaiseButton;
	private JButton btnLeave;
	private JButton btnStart;
	private JButton btnAllIn;
	
	/**
	 * Constructor for the GameDisplay class - takes a GameController
	 * and links it with a display
	 * @param c Target GameController to be synched with the GameDisplay
	 */
	public GameDisplay(GameController c) {
		super();
		drawGame();
		this.gameController = c;
	}
	/**
	 * Constructor for the GameDisplay class - takes a GameController and a 
	 * lastDisplay and links them to a GameDisplay
	 * @param c GameController to be linked
	 * @param lastDisplay Display to be linked
	 */
	public GameDisplay(GameController c, Display lastDisplay) {
		super(lastDisplay.getFrame());
		drawGame();
		this.gameController = c;
	}

	/**
	 * Method for drawing the game screen. Creates, positions and fills
	 * all graphical elements of the main game screen
	 */
	private void drawGame() {
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int X = (screen.width / 2) - (1020 / 2);
		int Y = (screen.height / 2) - (765 / 2);		
		
		frame.setBounds(X, Y, 1020, 725);
		frame.getContentPane().removeAll();

		ImagePanel GAMEPANEL = new ImagePanel(new ImageIcon(GUI.class.getResource("/images/Background_V4.png")).getImage());
		GAMEPANEL.setBackground(new Color(47, 79, 79));
		frame.getContentPane().add(GAMEPANEL, BorderLayout.CENTER);
		GAMEPANEL.setLayout(null);
		
		lblUserCard1 = new JLabel("");
		lblUserCard1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblUserCard1.setBounds(10, 551, 49, 70);
		GAMEPANEL.add(lblUserCard1);
		
		lblUserCard2 = new JLabel("");
		lblUserCard2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblUserCard2.setBounds(104, 551, 49, 70);
		GAMEPANEL.add(lblUserCard2);
		
		lblUserCard3 = new JLabel("");
		lblUserCard3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblUserCard3.setBounds(163, 551, 49, 70);
		GAMEPANEL.add(lblUserCard3);
		
		lblUserCard4 = new JLabel("");
		lblUserCard4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblUserCard4.setBounds(222, 551, 49, 70);
		GAMEPANEL.add(lblUserCard4);
		
		lblUserCard5 = new JLabel("");
		lblUserCard5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblUserCard5.setBounds(281, 551, 49, 70);
		GAMEPANEL.add(lblUserCard5);
		
		
		
		btnFoldButton = new JButton("Fold");
		btnFoldButton.setForeground(Color.DARK_GRAY);
		btnFoldButton.setBackground(new Color(240, 190, 80));
		btnFoldButton.setBounds(10, 632, 99, 32);
		btnFoldButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					gameController.fold();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		GAMEPANEL.add(btnFoldButton);
		
		btnCallButton = new JButton("Call");
		btnCallButton.setForeground(Color.DARK_GRAY);
		btnCallButton.setBackground(new Color(240, 190, 80));
		btnCallButton.setBounds(121, 632, 99, 32);
		btnCallButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					gameController.call();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});		
		GAMEPANEL.add(btnCallButton);
		
		btnRaiseButton = new JButton("Raise");
		btnRaiseButton.setForeground(Color.DARK_GRAY);
		btnRaiseButton.setBackground(new Color(240, 190, 80));
		btnRaiseButton.setBounds(232, 632, 99, 32);
		GAMEPANEL.add(btnRaiseButton);
		btnRaiseButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				boolean formattingError = false;
				
				// Bet formatting test.				
				String temp = betField.getText();
				for (int i = 0; i < temp.length(); i++) {
					if (!('0' <= temp.charAt(i) && temp.charAt(i) <= '9')) {
						formattingError = true;
					}
				}
				if(temp.equals(""))
					formattingError = true;
				
				if (formattingError) {
					JOptionPane.showMessageDialog(frame, "Please enter a valid bet.");
					formattingError = false;
				} 
				else{
					int raiseAmount = Integer.parseInt(betField.getText());
					
					if(raiseAmount > gameController.getMaxBet())
						JOptionPane.showMessageDialog(frame, "You can only raise up to "+gameController.getMaxBet()+".");
					else
						try {
							gameController.raise(raiseAmount);
						} catch (RemoteException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
				}
			}
		});
		
		btnLeave = new JButton("Leave");
		btnLeave.setForeground(Color.DARK_GRAY);
		btnLeave.setBackground(new Color(240, 190, 80));
		btnLeave.setBounds(678, 453, 68, 23);
		GAMEPANEL.add(btnLeave);
		btnLeave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					gameController.returnToLobby();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		
		btnStart = new JButton("Start");
		btnStart.setForeground(Color.DARK_GRAY);
		btnStart.setBackground(new Color(240, 190, 80));
		btnStart.setBounds(600, 453, 68, 23);
		GAMEPANEL.add(btnStart);
		btnStart.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				
				if (gameController.getNumberOfPlayers() < 2) {
					JOptionPane.showMessageDialog(frame, "Cannot start game with fewer than 2 players");
				}
				else {
					try {
						gameController.startFirstStreet();
						btnStart.setEnabled(false);
					} catch (RemoteException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}				
			}
			
		});
		
		chatOutgoing = new JTextField();
		chatOutgoing.setBounds(600, 642, 397, 22);
		GAMEPANEL.add(chatOutgoing);
		chatOutgoing.setColumns(10);
		chatOutgoing.addKeyListener(new KeyListener() {

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub
				if(arg0.getKeyCode() == KeyEvent.VK_ENTER) {
					try {
						gameController.sendMessage(chatOutgoing.getText());
					} catch (RemoteException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					chatOutgoing.setText(null);
				}
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
		
		lblPlayer_1 = new JLabel();
		lblPlayer_1.setForeground(Color.LIGHT_GRAY);
		lblPlayer_1.setBackground(new Color(47, 79, 79));
		lblPlayer_1.setText("Player 1");
		lblPlayer_1.setBounds(10, 11, 91, 22);
		GAMEPANEL.add(lblPlayer_1);
		
		lblPlayer_2 = new JLabel();
		lblPlayer_2.setForeground(Color.LIGHT_GRAY);
		lblPlayer_2.setBackground(new Color(47, 79, 79));
		lblPlayer_2.setText("Player 2");
		lblPlayer_2.setBounds(10, 151, 91, 22);
		GAMEPANEL.add(lblPlayer_2);
		
		lblPlayer_3 = new JLabel();
		lblPlayer_3.setForeground(Color.LIGHT_GRAY);
		lblPlayer_3.setBackground(new Color(47, 79, 79));
		lblPlayer_3.setText("Player 3");
		lblPlayer_3.setBounds(10, 289, 91, 22);
		GAMEPANEL.add(lblPlayer_3);
		
		lblPlayer_4 = new JLabel();
		lblPlayer_4.setForeground(Color.LIGHT_GRAY);
		lblPlayer_4.setBackground(new Color(47, 79, 79));
		lblPlayer_4.setText("Player 4");
		lblPlayer_4.setBounds(547, 11, 91, 22);
		GAMEPANEL.add(lblPlayer_4);
		
		lblPlayer_5 = new JLabel();
		lblPlayer_5.setForeground(Color.LIGHT_GRAY);
		lblPlayer_5.setBackground(new Color(47, 79, 79));
		lblPlayer_5.setText("Player 5");
		lblPlayer_5.setBounds(547, 151, 91, 22);
		GAMEPANEL.add(lblPlayer_5);
		
		chatIncoming = new JTextArea();
		chatIncoming.setText("Chat Area");
		chatIncoming.setBounds(600, 487, 397, 150);
		chatIncoming.setEditable(false);
		chatIncoming.setLineWrap(true);
		chatIncoming.setVisible(true);
		GAMEPANEL.add(chatIncoming);
		
		chatIncomingScrollable = new JScrollPane(chatIncoming, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		chatIncomingScrollable.setBounds(600, 487, 398, 150);
		chatIncomingScrollable.setVisible(true);
		GAMEPANEL.add(chatIncomingScrollable);
		
		
		JLabel lblPotText = new JLabel("Pot:");
		lblPotText.setForeground(Color.LIGHT_GRAY);
		lblPotText.setBackground(new Color(47, 79, 79));
		lblPotText.setBounds(819, 450, 46, 14);
		GAMEPANEL.add(lblPotText);
		
		lblPot = new JLabel("$999");
		lblPot.setBackground(new Color(47, 79, 79));
		lblPot.setForeground(Color.LIGHT_GRAY);
		lblPot.setFont(new Font("Arial", Font.BOLD, 29));
		lblPot.setBounds(889, 433, 108, 43);
		GAMEPANEL.add(lblPot);
		
		
		betField = new JTextField();
		betField.setBounds(346, 638, 86, 20);
		GAMEPANEL.add(betField);
		betField.setColumns(10);
			
		btnAllIn = new JButton("ALL-IN!");
		btnAllIn.setForeground(Color.DARK_GRAY);
		btnAllIn.setBackground(new Color(240, 190, 80));
		btnAllIn.setBounds(442, 632, 99, 32);
		GAMEPANEL.add(btnAllIn);
		btnAllIn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				try {
					gameController.allIn();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		
		JLabel lblBetText = new JLabel();
		lblBetText.setForeground(Color.LIGHT_GRAY);
		lblBetText.setBackground(new Color(47, 79, 79));
		lblBetText.setText("Bet");
		lblBetText.setBounds(346, 615, 86, 22);
		GAMEPANEL.add(lblBetText);		
		
		lblPlayer1C1 = new JLabel("");
		lblPlayer1C1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer1C1.setBounds(10, 42, 49, 70);
		GAMEPANEL.add(lblPlayer1C1);
		
		lblPlayer1C2 = new JLabel("");
		lblPlayer1C2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer1C2.setBounds(104, 42, 49, 70);
		GAMEPANEL.add(lblPlayer1C2);
		
		lblPlayer1C3 = new JLabel("");
		lblPlayer1C3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer1C3.setBounds(163, 42, 49, 70);
		GAMEPANEL.add(lblPlayer1C3);
		
		lblPlayer1C4 = new JLabel("");
		lblPlayer1C4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer1C4.setBounds(222, 42, 49, 70);
		GAMEPANEL.add(lblPlayer1C4);
		
		lblPlayer1C5 = new JLabel("");
		lblPlayer1C5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer1C5.setBounds(281, 42, 49, 70);
		GAMEPANEL.add(lblPlayer1C5);
		
		lblPlayer2C1 = new JLabel("");
		lblPlayer2C1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer2C1.setBounds(10, 181, 49, 70);
		GAMEPANEL.add(lblPlayer2C1);
		
		lblPlayer2C2 = new JLabel("");
		lblPlayer2C2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer2C2.setBounds(104, 181, 49, 70);
		GAMEPANEL.add(lblPlayer2C2);
		
		lblPlayer2C3 = new JLabel("");
		lblPlayer2C3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer2C3.setBounds(163, 181, 49, 70);
		GAMEPANEL.add(lblPlayer2C3);
		
		lblPlayer2C4 = new JLabel("");
		lblPlayer2C4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer2C4.setBounds(222, 181, 49, 70);
		GAMEPANEL.add(lblPlayer2C4);
		
		lblPlayer2C5 = new JLabel("");
		lblPlayer2C5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer2C5.setBounds(281, 181, 49, 70);
		GAMEPANEL.add(lblPlayer2C5);
		
		lblPlayer3C1 = new JLabel("");
		lblPlayer3C1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer3C1.setBounds(10, 314, 49, 70);
		GAMEPANEL.add(lblPlayer3C1);
		
		lblPlayer3C2 = new JLabel("");
		lblPlayer3C2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer3C2.setBounds(104, 314, 49, 70);
		GAMEPANEL.add(lblPlayer3C2);
		
		lblPlayer3C3 = new JLabel("");
		lblPlayer3C3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer3C3.setBounds(163, 314, 49, 70);
		GAMEPANEL.add(lblPlayer3C3);
		
		lblPlayer3C4 = new JLabel("");
		lblPlayer3C4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer3C4.setBounds(222, 314, 49, 70);
		GAMEPANEL.add(lblPlayer3C4);
		
		lblPlayer3C5 = new JLabel("");
		lblPlayer3C5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer3C5.setBounds(281, 314, 49, 70);
		GAMEPANEL.add(lblPlayer3C5);
		
		lblPlayer4C1 = new JLabel("");
		lblPlayer4C1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer4C1.setBounds(548, 42, 49, 70);
		GAMEPANEL.add(lblPlayer4C1);
		
		lblPlayer4C2 = new JLabel("");
		lblPlayer4C2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer4C2.setBounds(642, 42, 49, 70);
		GAMEPANEL.add(lblPlayer4C2);
		
		lblPlayer4C3 = new JLabel("");
		lblPlayer4C3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer4C3.setBounds(701, 42, 49, 70);
		GAMEPANEL.add(lblPlayer4C3);
		
		lblPlayer4C4 = new JLabel("");
		lblPlayer4C4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer4C4.setBounds(760, 42, 49, 70);
		GAMEPANEL.add(lblPlayer4C4);
		
		lblPlayer4C5 = new JLabel("");
		lblPlayer4C5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer4C5.setBounds(819, 42, 49, 70);
		GAMEPANEL.add(lblPlayer4C5);
		
		lblPlayer5C1 = new JLabel("");
		lblPlayer5C1.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer5C1.setBounds(547, 181, 49, 70);
		GAMEPANEL.add(lblPlayer5C1);
		
		lblPlayer5C2 = new JLabel("");
		lblPlayer5C2.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer5C2.setBounds(641, 181, 49, 70);
		GAMEPANEL.add(lblPlayer5C2);
		
		lblPlayer5C3 = new JLabel("");
		lblPlayer5C3.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer5C3.setBounds(700, 181, 49, 70);
		GAMEPANEL.add(lblPlayer5C3);
		
		lblPlayer5C4 = new JLabel("");
		lblPlayer5C4.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer5C4.setBounds(759, 181, 49, 70);
		GAMEPANEL.add(lblPlayer5C4);
		
		lblPlayer5C5 = new JLabel("");
		lblPlayer5C5.setIcon(new ImageIcon(GameTable.class.getResource("/images/Card_Images/card-placeholder.png")));
		lblPlayer5C5.setBounds(818, 181, 49, 70);
		GAMEPANEL.add(lblPlayer5C5);
		
		lblPlayer1Portrait = new JLabel("");
		lblPlayer1Portrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblPlayer1Portrait.setBounds(346, 42, 50, 43);
		GAMEPANEL.add(lblPlayer1Portrait);
		
		lblPlayer2Portrait = new JLabel("");
		lblPlayer2Portrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblPlayer2Portrait.setBounds(346, 181, 50, 43);
		GAMEPANEL.add(lblPlayer2Portrait);
		
		lblPlayer3Portrait = new JLabel("");
		lblPlayer3Portrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblPlayer3Portrait.setBounds(346, 314, 50, 43);
		GAMEPANEL.add(lblPlayer3Portrait);
		
		lblPlayer4Portrait = new JLabel("");
		lblPlayer4Portrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblPlayer4Portrait.setBounds(885, 42, 50, 43);
		GAMEPANEL.add(lblPlayer4Portrait);
		
		lblPlayer5Portrait = new JLabel("");
		lblPlayer5Portrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblPlayer5Portrait.setBounds(885, 181, 50, 43);
		GAMEPANEL.add(lblPlayer5Portrait);
				
		lblPlayer1Money = new JLabel();
		lblPlayer1Money.setForeground(Color.LIGHT_GRAY);
		lblPlayer1Money.setBackground(new Color(47, 79, 79));
		lblPlayer1Money.setText("$$$$");
		lblPlayer1Money.setVerticalAlignment(SwingConstants.TOP);
		lblPlayer1Money.setHorizontalAlignment(SwingConstants.LEFT);
		lblPlayer1Money.setBounds(335, 90, 120, 55);
		GAMEPANEL.add(lblPlayer1Money);
		
		lblPlayer2Money = new JLabel();
		lblPlayer2Money.setText("$$$$");
		lblPlayer2Money.setForeground(Color.LIGHT_GRAY);
		lblPlayer2Money.setBackground(new Color(47, 79, 79));
		lblPlayer2Money.setVerticalAlignment(SwingConstants.TOP);
		lblPlayer2Money.setHorizontalAlignment(SwingConstants.LEFT);
		lblPlayer2Money.setBounds(335, 229, 120, 55);
		GAMEPANEL.add(lblPlayer2Money);
		
		lblPlayer3Money = new JLabel();
		lblPlayer3Money.setText("$$$$");
		lblPlayer3Money.setForeground(Color.LIGHT_GRAY);
		lblPlayer3Money.setBackground(new Color(47, 79, 79));
		lblPlayer3Money.setVerticalAlignment(SwingConstants.TOP);
		lblPlayer3Money.setHorizontalAlignment(SwingConstants.LEFT);
		lblPlayer3Money.setBounds(335, 362, 120, 55);
		GAMEPANEL.add(lblPlayer3Money);
		
		lblPlayer4Money = new JLabel();
		lblPlayer4Money.setText("$$$$");
		lblPlayer4Money.setForeground(Color.LIGHT_GRAY);
		lblPlayer4Money.setBackground(new Color(47, 79, 79));
		lblPlayer4Money.setVerticalAlignment(SwingConstants.TOP);
		lblPlayer4Money.setHorizontalAlignment(SwingConstants.LEFT);
		lblPlayer4Money.setBounds(874, 90, 120, 55);
		GAMEPANEL.add(lblPlayer4Money);
		
		lblPlayer5Money = new JLabel();
		lblPlayer5Money.setText("$$$$");
		lblPlayer5Money.setForeground(Color.LIGHT_GRAY);
		lblPlayer5Money.setBackground(new Color(47, 79, 79));
		lblPlayer5Money.setVerticalAlignment(SwingConstants.TOP);
		lblPlayer5Money.setHorizontalAlignment(SwingConstants.LEFT);
		lblPlayer5Money.setBounds(874, 229, 120, 55);
		GAMEPANEL.add(lblPlayer5Money);
		
		lblUser = new JLabel();
		lblUser.setForeground(Color.LIGHT_GRAY);
		lblUser.setBackground(new Color(47, 79, 79));
		lblUser.setText("RCAIMANO");
		lblUser.setBounds(10, 518, 143, 22);
		GAMEPANEL.add(lblUser);
				
		lblAnte = new JLabel();
		lblAnte.setForeground(Color.LIGHT_GRAY);
		lblAnte.setBackground(new Color(47, 79, 79));
		lblAnte.setText("Ante:");
		lblAnte.setBounds(819, 358, 68, 22);
		GAMEPANEL.add(lblAnte);
		
		lblMaxBet = new JLabel();
		lblMaxBet.setForeground(Color.LIGHT_GRAY);
		lblMaxBet.setBackground(new Color(47, 79, 79));
		lblMaxBet.setText("Max Bet:");
		lblMaxBet.setBounds(819, 400, 68, 22);
		GAMEPANEL.add(lblMaxBet);
		
		lblAnteValue = new JLabel();
		lblAnteValue.setForeground(Color.LIGHT_GRAY);
		lblAnteValue.setBackground(new Color(47, 79, 79));
		lblAnteValue.setFont(new Font("Arial", Font.PLAIN, 25));
		lblAnteValue.setText("999");
		lblAnteValue.setBounds(889, 345, 108, 32);
		GAMEPANEL.add(lblAnteValue);
		
		lblMaxBetValue = new JLabel();
		lblMaxBetValue.setForeground(Color.LIGHT_GRAY);
		lblMaxBetValue.setBackground(new Color(47, 79, 79));
		lblMaxBetValue.setText("999");
		lblMaxBetValue.setFont(new Font("Arial", Font.PLAIN, 25));
		lblMaxBetValue.setBounds(889, 390, 108, 32);
		GAMEPANEL.add(lblMaxBetValue);
		
		lblUserPortrait = new JLabel("");
		lblUserPortrait.setIcon(new ImageIcon(GameTable.class.getResource("/images/PersonIcon.png")));
		lblUserPortrait.setBounds(346, 551, 50, 43);
		GAMEPANEL.add(lblUserPortrait);
		
		lblUserMoney = new JLabel();
		lblUserMoney.setText("999 $");
		lblUserMoney.setForeground(Color.LIGHT_GRAY);
		lblUserMoney.setFont(new Font("Arial", Font.BOLD, 23));
		lblUserMoney.setBackground(new Color(47, 79, 79));
		lblUserMoney.setVerticalAlignment(SwingConstants.TOP);
		lblUserMoney.setHorizontalAlignment(SwingConstants.LEFT);
		lblUserMoney.setBounds(400, 551, 180, 43);
		GAMEPANEL.add(lblUserMoney);
		
		frame.setVisible(true);

	}
	
	/**
	 * Set the name of the player to the appropriate location on the game screen
	 * @param seat the location of the player on the table
	 * @param name the username of the player to be displayed
	 */
	public void setPlayerName(int seat, String name) {
		switch (seat) {
		case 0: lblUser.setText(name); break;
		case 1: lblPlayer_1.setText(name); break;
		case 2: lblPlayer_2.setText(name); break;
		case 3: lblPlayer_3.setText(name); break;
		case 4: lblPlayer_4.setText(name); break;
		case 5: lblPlayer_5.setText(name); break;
		default: break;
		}
	}
	
	/**
	 * Set the money player has to the appropriate location on the game screen
	 * @param seat the location of the player on the table
	 * @param money the amount of money to be displayed
	 */
	public void setPlayerMoney(int seat, String money) {
		switch(seat) {
		case 0: lblUserMoney.setText(money); break;
		case 1: lblPlayer1Money.setText(money); break;
		case 2: lblPlayer2Money.setText(money); break;
		case 3: lblPlayer3Money.setText(money); break;
		case 4: lblPlayer4Money.setText(money); break;
		case 5: lblPlayer5Money.setText(money); break;
		default: break;
		}
	}
	
	public JTextArea getChatIncoming() {
		return chatIncoming;
	}
	
	/**
	 * Set the pot value on the screen to the given pot value
	 * @param pot amount to update pot to
	 */
	public void setPot(int pot) {
		lblPot.setText("$" + pot);
	}
	
	/**
	 * Set the ante value on the screen to the given ante value
	 * @param anteValue amount to update anteValue to
	 */
	public void setAnteValue(int anteValue) {
		lblAnteValue.setText("$" + anteValue);
	}
	
	/**
	 * Set the max bet value on the screen to the given max bet value
	 * @param maxBetValue amount to update maximum bet to
	 */
	public void setMaxBetValue(int maxBetValue) {
		lblMaxBetValue.setText("$" + maxBetValue);
	}
	
	/**
	 * Set the player portait to reflect the appropriate status
	 * @param seat the location of the player at the table
	 * @param status the status to be updated
	 */
	public void setPlayerPortrait(int seat, int status){
		String url = "/images/";
		ImageIcon icon = null;
		
		switch(status){
		//if the status is -1, player is INACTIVE, show red icon
		case -1:
			url = url + "PersonIcon_red.png";
			break;
		//if the status is 0, player is WAITING_FOR_TURN, show yellow icon
		case 0:
			url = url + "PersonIcon_yellow.png";
			break;
		//if the status is 1, player is IN_TURN, show green icon
		case 1:
			url = url + "PersonIcon_green.png";
			break;
		//if the status is 2, there is no player, show grey icon
		case 2:
			url = url + "PersonIcon_gray.png";
			break;
		//if the status is 4, the play has WON, show blue icon
		case 4:
			url = url + "PersonIcon_blue.png";
			break;
		default: url = null; break;
		}
		
		if (url == null) {
			icon = null;
		}
		else {
			System.out.println("The URL is : " + url);
			icon = new ImageIcon(GameTable.class.getResource(url));
		}
		
		switch (seat) {
		case 0:
			lblUserPortrait.setIcon(icon); 
			break;
		case 1:
			lblPlayer1Portrait.setIcon(icon); 
			break;
		case 2:
			lblPlayer2Portrait.setIcon(icon); 
			break;
		case 3:
			lblPlayer3Portrait.setIcon(icon); 
			break;
		case 4:
			lblPlayer4Portrait.setIcon(icon); 
			break;
		case 5:
			lblPlayer5Portrait.setIcon(icon); 
			break;
		default: break;
		}
	}
	
	/**
	 * Set the card image for a specific location
	 * @param seat the location of the player on the table
	 * @param cardNumber the location of the card in the players hand
	 * @param card the card to be displayed
	 */
	public void setCard(int seat, int cardNumber, Card card) {
		String url = "/images/Card_Images/";
		ImageIcon icon = null;
		
		//if the card is not null, set the appropriate image
		if (card != null){
			//if card is face up get the exact card image
			if(card.isFaceUp()){
				//get the suit value of the card
				switch (card.getSuit()){
				case DIAMONDS:
					url = url + "Diamonds/";
					break;
					
				case CLUBS:
					url = url + "Clubs/";
					break;
					
				case HEARTS:
					url = url + "Hearts/";
					break;
					
				case SPADES:
					url = url + "Spades/";
					break;
				}

				//get the numerical face value of the card image
				url = url + "" +card.getCardValue()+ ".png";
			}

			//if card is face down just show back of card
			else{
				url = url + "back_blue.png";
			}	
		}
		//if the card is null, the url is null
		else{
			url = null;
		}
		
		//if the url is null, set a null icon
		if (url == null) {
			icon = null;
		}
		
		//otherwise set the icon to that found at the specific url
		else {
			icon = new ImageIcon(GameTable.class.getResource(url));
		}
		
		//set the found icon of the card to the appropriate location
		switch (seat) {
		case 0:
			switch(cardNumber) {
			case 1: lblUserCard1.setIcon(icon); break;
			case 2: lblUserCard2.setIcon(icon); break;
			case 3: lblUserCard3.setIcon(icon); break;
			case 4: lblUserCard4.setIcon(icon); break;
			case 5: lblUserCard5.setIcon(icon); break;
			default: break;
			} break;
		case 1:
			switch(cardNumber) {
			case 1: lblPlayer1C1.setIcon(icon); break;
			case 2: lblPlayer1C2.setIcon(icon); break;
			case 3: lblPlayer1C3.setIcon(icon); break;
			case 4: lblPlayer1C4.setIcon(icon); break;
			case 5: lblPlayer1C5.setIcon(icon); break;
			default: break;
			} break;
		case 2:
			switch(cardNumber) {
			case 1: lblPlayer2C1.setIcon(icon); break;
			case 2: lblPlayer2C2.setIcon(icon); break;
			case 3: lblPlayer2C3.setIcon(icon); break;
			case 4: lblPlayer2C4.setIcon(icon); break;
			case 5: lblPlayer2C5.setIcon(icon); break;
			default: break;
			} break;
		case 3:
			switch(cardNumber) {
			case 1: lblPlayer3C1.setIcon(icon); break;
			case 2: lblPlayer3C2.setIcon(icon); break;
			case 3: lblPlayer3C3.setIcon(icon); break;
			case 4: lblPlayer3C4.setIcon(icon); break;
			case 5: lblPlayer3C5.setIcon(icon); break;
			default: break;
			} break;
		case 4:
			switch(cardNumber) {
			case 1: lblPlayer4C1.setIcon(icon); break;
			case 2: lblPlayer4C2.setIcon(icon); break;
			case 3: lblPlayer4C3.setIcon(icon); break;
			case 4: lblPlayer4C4.setIcon(icon); break;
			case 5: lblPlayer4C5.setIcon(icon); break;
			default: break;
			} break;
		case 5:
			switch(cardNumber) {
			case 1: lblPlayer5C1.setIcon(icon); break;
			case 2: lblPlayer5C2.setIcon(icon); break;
			case 3: lblPlayer5C3.setIcon(icon); break;
			case 4: lblPlayer5C4.setIcon(icon); break;
			case 5: lblPlayer5C5.setIcon(icon); break;
			default: break;
			} break;
		default: break;
		}
	}

	/**
	 * Set the player's fold, call, raise and all in button to inactive
	 */
	public void setButtonsInactive() {
		btnFoldButton.setEnabled(false);
		btnCallButton.setEnabled(false);
		btnRaiseButton.setEnabled(false);
		btnLeave.setEnabled(false);
		btnStart.setEnabled(false);
		btnAllIn.setEnabled(false);	
	}
	
	/**
	 * Set the player's fold, call, raise and all in button to active
	 */
	public void setButtonsActive() {
		btnFoldButton.setEnabled(true);
		btnCallButton.setEnabled(true);
		btnRaiseButton.setEnabled(true);
		btnAllIn.setEnabled(true);	
	}
	
	/**
	 * Enable the START button to be clickable
	 * @param b if true enable button, if false disable it
	 */
	public void startEnabled(boolean b) {
		btnStart.setEnabled(b);
	}
	
	/**
	 * Enable the LEAVE button to be clickable
	 * @param b if true enable button, if false disable it
	 */
	public void leaveEnabled(boolean b) {
		btnLeave.setEnabled(b);
	}
	
	/**
	 * Refreshes the chat interface
	 * @param messages ArrayList of messages to be displayed in the chat
	 */
	public void updateChat(ArrayList<String> messages) {
		chatIncoming.setText(null);
		if (messages.size() != 0) {
			chatIncoming.setText(messages.get(0));
		}
		for (int i = 1; i < messages.size(); i++) {
			chatIncoming.setText(chatIncoming.getText() + "\n" + messages.get(i));
		}
		
		JScrollBar vbar = chatIncomingScrollable.getVerticalScrollBar();
		boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());

		if( autoScroll ) chatIncoming.setCaretPosition( chatIncoming.getDocument().getLength() );		
		
	}
	

}
